package com.ywy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ywy.entity.User;
import com.ywy.shiro.AccountProfile;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * 基础Controller
 *
 * @author ywy
 * @date 2020-05-27 13:51
 */
public class BaseController {
    @Autowired
    public HttpServletRequest req;

    /**
     * 获取page信息
     * @return
     */
    public Page getPage() {
        int pn = ServletRequestUtils.getIntParameter(req, "pn", 1);
        int size = ServletRequestUtils.getIntParameter(req, "size", 10);
        return new Page(pn, size);
    }

    /**
     * 获取登录用户
     * @return
     */
    protected AccountProfile getProfile() {
        return (AccountProfile) SecurityUtils.getSubject().getPrincipal();
    }

    /**
     * 获取登录用户id
     * @return
     */
    protected Integer getProfileId() {
        return getProfile().getId();
    }
}
